<?
class uploadFile{
	
	protected $file;
	protected $fileName;
	protected $filePath;
	
	public function __construct($iFile = NULL){
		
		
		if($iFile != NULL){
			
				$this -> file = $iFile;
		
		
		}
	}
	
	
	public function setName($iName){
	
		$this -> fileName = $iName;
	
	}
	
	public function getName($ext = true){
		
		if($ext){
		return $this -> fileName . $this -> getExt();
		}else{
		return $this -> fileName;
		}
	}
	
	
	public function setPath($iPath){
	
		$this -> filePath = $iPath;
	
	}
	
	public function getPath(){
	
		return $this -> filePath;
	
	}

	
	private function getExt(){
		
		
		$pos = strrpos($this -> file['name'],'.');
		$ext=substr($this -> file['name'],$pos,strlen($this -> file['name']));
		
		return $ext;
		
	}
	
	public function getFullPath(){
		
		return $this -> filePath . '/' . $this -> fileName . $this -> getExt();
	
	}
	
	
	public function upload(){
		
		
		return move_uploaded_file($this -> file['tmp_name'], $this -> getFullPath());
	
	}
	
	public function copyTo($fileName, $filePath){
	
		copy($this -> getFullPath(), $filePath . '/' . $fileName . $this -> getExt());
		
		$this -> setPath($filePath);
		$this -> setName($fileName);
		
	}

	public function resize($x)
	{
		
		chmod($this -> getFullPath(),0777);
		
		
		if($groote = getimagesize($this -> getFullPath())) 
			{
				list($breedte,$hoogte) = $groote;
				$mimeType = $groote['mime'];

				//controleren of het wel een foto is 
				switch($mimeType)
				{
				
					case 'image/jpeg' || 'image/jpg':
						$verkleinen = imagecreatefromjpeg($this -> getFullPath());
						
						break;
					case 'image/gif':
						$verkleinen = imagecreatefromgif($this -> getFullPath());
						break;
					case 'image/png':
						$verkleinen = imagecreatefrompng($this -> getFullPath());
						break;
					case 'image/bmp':
						$verkleinen = imagecreatefrombmp($this -> getFullPath());
						break;
				}
				
				//controlere of de breedte en de hoogte zijn gezet
				
				if (isset($breedte,$hoogte))
				{
					
						$opp = $hoogte / $breedte;
						$nHoogte = $opp * $x;
					
					
				}
				$verkleind = imagecreatetruecolor($x, $nHoogte);        
				imagecopyresampled($verkleind, $verkleinen, 0, 0, 0, 0, $x, $nHoogte, $breedte, $hoogte);
				
				
				
				switch($mimeType)
				{
					case 'image/jpeg' || 'image/jpg':
						imagejpeg($verkleind,$this -> getFullPath(),100);
						break;
					case 'image/gif':
						imagegif($verkleind,$this -> getFullPath());
						break;
					case 'image/png':
						imagepng($verkleind,$this -> getFullPath());
						break;
					case 'image/bmp':
						imagebmp($verkleind,$this -> getFullPath());
						break;
				}

			}
		}




}


?>